<h2>Attachments</h2>
<div class='well' ng-repeat='a in attachments'>
  <form ng-submit='updateAttachment(a)' name='adminAttachmentForm[$index]'>
    <div class='form-group'>
      <label for='name-{{a.aid}}'>Title</label>
      <input name='name' id='name-{{a.aid}}' class='form-control'
        ng-model='a.filename' required>
    </div>
    <div class='file-upload'>
      <label for='dl-{{a.aid}}'>File</label>
      <div class='hash-link'>
        <div ng-click='replace(a)' id='dl-{{a.aid}}' class='hash-dl form-control' target='_blank'>{{a.aid}}</div>
      </div>
    </div>
    <label ng-show='a.challenges.length' for='ch-{{a.aid}}'>Challenges</label>
    <div id='ch-{{a.aid}}' class='challenge-list'>
      <div ng-repeat='ch in a.challenges'>
        <a class='btn-info btn challenge-item' ng-href='/admin/challenge/{{ch.cid}}'>{{ch.name}}</a>
      </div>
    </div>
    <input type='submit' value='Save' class='btn btn-primary'>
    <div>
      <input type='button' value='Delete' class='btn btn-danger btn-delete'
        ng-click='deleteAttachment(a)' ng-disabled='invalidForm($index)'>
    </div>
  </form>
</div>
<div class='well'>
  <form ng-submit='addAttachment()' name='adminAttachmentForm'>
    <div class='form-group'>
      <label for='new-name'>Title</label>
      <input name='filename' id='new-name' class='form-control'
        ng-model='newAttachment.filename' required>
    </div>
    <div class='file-upload'>
      <label for='new-aid'>File</label>
      <div class='hash-link'>
        <div ng-click='addfile()' id='new-aid' class='hash-dl form-control' target='_blank'>
          <div ng-show='newAttachment.aid' ng-bind='newAttachment.aid'></div>
          <div ng-hide='newAttachment.aid'><i>No File Selected</i></div>
        </div>
      </div>
    </div>
    <input type='submit' value='Add New' class='btn btn-primary'
      ng-disabled='adminAttachmentForm.$invalid || !newAttachment.aid'>
  </form>
</div>
